/**
 * Copyright (c) 华南农业大学信息学院蔡超敏2015版权所有
 * 
 * 文件创建时间：2015年4月9日
 */
package org.scauinfo.fpos.service.impl;

import java.io.Serializable;
import java.util.List;

import org.scauinfo.fpos.dao.impl.MemberDao;
import org.scauinfo.fpos.service.MemberService;
import org.scauinfo.fpos.vo.Member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 蔡超敏
 * 
 */
@Service
public class MemberServiceImpl implements MemberService {

	@Autowired
	private MemberDao memberDao;

	@Override
	public void saveMember(Member member) {
		memberDao.save(member);
	}

	@Override
	public void updateMember(Member member) {
		memberDao.update(member);
	}

	@Override
	public void deleteMember(int id) {
		Member member = memberDao.get(id);
		member.setMemberpermission(null);
		memberDao.delete(member);
	}

	@Override
	public List<Member> findAllMember(int page, int rows, String sort,
			String order) {
		return memberDao.findAll(page, rows, sort, order);
	}

	@Override
	public int getTotal() {
		return memberDao.countAll();
	}

	@Override
	public Member find(String memberId) {
		String hql = "from Member as p where p.memberId= '" + memberId+"'";

		List<Member> list = memberDao.find(hql);

		if (list != null & list.size() > 0)
			return list.get(0);

		return null;
	}

	@Override
	public boolean isExist(String memberId) {
		boolean flag = false;
		String hql = "from Member as p where p.memberId=" + memberId;
		if (memberDao.find(hql).size() > 0) {
			flag = true;
		}
		return flag;
	}

	@Override
	public Member get(Serializable id) {
		return memberDao.get(id);
	}

}
